import router from '@/router'
const user = {
  state: {
    roles: [],
    flagRole: false,
    userInfo: {},
    config: {}
  },

  mutations: {
    SET_ROLES: (state, roles) => {
      state.roles = roles
    },
    SET_FLAG: (state, res) => {
      state.flagRole = res
    },
    SET_USERINFO: (state, res) => {
      state.userInfo = res
    },
    SET_CONFIG: (state, res) => {
      state.config = res
    }
  },
  actions: {
    // 登录
    userPower ({ commit }, userInfo) {
      return new Promise((resolve, reject) => {
        const sidebar = router.options.routes.filter(item => item.path !== '*')[0].children
        commit('SET_ROLES', sidebar)
        resolve(sidebar)
      })
    },
    // 获取用户信息
    GetUserConfig ({ commit }, data) {
      return new Promise((resolve, reject) => {
        resolve(true)
      })
    }
  }
}

export default user
